<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/2/2
 * Time: 13:09
 */

namespace app\admin\controller\common;
use think\Config;
use think\Db;

class Admin
{
    #验证用户是否登入
    public $userId;
    public $url;
    public function __construct()
    {
       if(is_null(session('dsihUGJKJOIJiojf*&%$6uig12@#$sdD'))){
           echo '<script>location.href = "/admin/sys/login"</script>';
       }
       else{
           $this ->userId = session('dsihUGJKJOIJiojf*&%$6uig12@#$sdD');
           $this ->url =  \request() ->controller().'/'.\request() ->action();
       }

       //设置当前导航名称
        $user_name= Db::table('bg_sysmenu')
            ->alias('nav')
            ->where('url',$this ->url)
            ->join('q_words parent','nav.parentId = parent.id')
            ->field("
            nav.name as name,
            parent.name as parentname,
            nav.id as navid
            ")
            ->find();

       !is_null($user_name) && Config::set('this_user_name',"{$user_name['parentname']} > {$user_name['name']}");
       #判断访问权限
        if (!is_null($user_name)) {//检测这个url纯在不

            //查询访问权限
            $jian_ce = Db::table('bg_userandmenu')
                ->where('user_id',$this->userId)
                ->where('menu_id',$user_name['navid'])->count();

            /*if ($jian_ce == 0) {
                echo '<button onclick="parent.layer.close(parent.layer.getFrameIndex(window.name));">返回页面</button>';
                exit('无访问权限');
            }*/
        }

    }
}